package com.property.manage.controller.fee;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.fee.PropertyVo;
import com.property.manage.model.system.SysSet;
import com.property.manage.service.fee.PropertyService;
import com.property.manage.service.system.SysSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/16
 */
@Api(tags = "物业费管理")
@RestController
@RequestMapping("/property")
@Validated
@AllArgsConstructor
public class PropertyController {
    @Autowired
    private PropertyService propertyService;
    @Autowired
    private SysSetService sysSetService;

    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(@ApiParam("楼栋编号") @RequestParam("buildingId") @NotNull(message = "楼栋编号为空") Integer buildingId,
                    @ApiParam("档次编号") @RequestParam("gradeId") @NotNull(message = "档次为空") Integer gradeId,
                    @ApiParam("下次缴费时间") @RequestParam(value = "nextPayDate", required = false) LocalDate nextPayDate,
                    @ApiParam("姓名") @RequestParam("name") @NotNull(message = "姓名为空") String name,
                    @ApiParam("应缴费用") @RequestParam("shouldPay") @NotNull(message = "姓名为空") BigDecimal shouldPay,
                    @ApiParam("联系方式") @RequestParam("mobile") @NotNull(message = "联系方式为空") String mobile){
        propertyService.add(buildingId, gradeId, nextPayDate, name, mobile,shouldPay);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@ApiParam("编号") @RequestParam("id") @NotNull(message = "编号为空") Integer id,
                       @ApiParam("楼栋编号") @RequestParam("buildingId") @NotNull(message = "楼栋编号为空") Integer buildingId,
                       @ApiParam("档次编号") @RequestParam("gradeId") @NotNull(message = "档次为空") Integer gradeId,
                       @ApiParam("应缴费用") @RequestParam("shouldPay") @NotNull(message = "姓名为空") BigDecimal shouldPay,
                       @ApiParam("下次缴费时间") @RequestParam(value = "nextPayDate", required = false) LocalDate nextPayDate,
                       @ApiParam("姓名") @RequestParam("name") @NotNull(message = "姓名为空") String name,
                       @ApiParam("联系方式") @RequestParam("mobile") @NotNull(message = "联系方式为空") String mobile){
        propertyService.update(id, buildingId, gradeId, nextPayDate, name, mobile,shouldPay);
    }

    @ApiOperation("列表")
    @GetMapping("/page")
    public CustomPage<PropertyVo> userPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                           @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                           @ApiParam("小区编号") @RequestParam(value = "villageId", required = false) Integer villageId,
                                           @ApiParam("姓名") @RequestParam(value = "name", required = false) String name){
        return propertyService.propertyPage(pageNo, pageSize, villageId, name);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("编号") @RequestParam("id") @NotNull(message = "编号为空") Integer id){
        propertyService.delete(id);
    }

    @ApiOperation("档次类型")
    @GetMapping("/grade/type")
    public List<SysSet> type(){
        return sysSetService.getSysSets(SysSet.TYPE_MANAGE_FEE_GRADE);
    }


    @ApiOperation("物业费划扣")
    @PostMapping("/deduction")
    public void propertyDeduction(@ApiIgnore @RequestParam("userId") @NotNull(message = "您尚未登录") Integer userId,
                                  @ApiParam("小区编号") @RequestParam("villageId") @NotNull(message = "小区编号为空") Integer villageId,
                                  @ApiParam("划扣年份") @RequestParam("year") @NotNull(message = "划扣年份为空") Integer year,
                                  @ApiParam("划扣月份") @RequestParam("month") @NotNull(message = "划扣月份为空") Integer month){

        propertyService.propertyDeduction(userId, villageId, year, month);

    }
}
